package com.refusea.commons.utils

import java.util.Base64
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec


/**
 * @author Zhang Yan, 2023/9/7
 **/
object Digests {

    private const val HMAC_SHA_1 = "HmacSHA1"

    @JvmStatic
    fun base64HmacSha1(data: String, key: ByteArray): String {
        val mac = Mac.getInstance(HMAC_SHA_1)
        mac.init(SecretKeySpec(key, HMAC_SHA_1))
        return Base64.getEncoder().encodeToString(mac.doFinal(data.toByteArray()))
    }
}
